package core

import (
	"fmt"
	"github.com/sirupsen/logrus"
	"os"
)

var log *logrus.Logger

func InitLog() {
	log = logrus.New()
	if CONF.Log.Output == "stdout" {
		log.SetOutput(os.Stdout)
	} else {
		// TODO filename
		fmt.Println("set log.output to file: %s", CONF.Log.Output)
	}

	switch CONF.Log.Level {
	case "debug":
		log.SetLevel(logrus.DebugLevel)
		break
	case "error":
		log.SetLevel(logrus.ErrorLevel)
		break
	case "fatal":
		log.SetLevel(logrus.FatalLevel)
		break
	case "info":
		log.SetLevel(logrus.InfoLevel)
		break
	case "panic":
		log.SetLevel(logrus.PanicLevel)
		break
	case "warn":
		log.SetLevel(logrus.WarnLevel)
		break
	case "trace":
		log.SetLevel(logrus.TraceLevel)
		break
	default:
		log.SetLevel(logrus.InfoLevel)
		break
	}
}

func Info(msg string) {
	log.Info(msg)
}

func Error(msg string) {
	log.Error(msg)
}
